import emitter from "../utils/eventbus";
import * as d3 from "d3";

/**
 * 
 * @param $ 
 * @param height 
 * @param width 
 * @param d3CanvasRef 
 * @returns 
 */
//初始化裸眼井（增）
export function initOpenHole($: any, height: number, width: number, d3CanvasRef: any) {
    let id: string = $.attr("id");
    const d3Canvas = d3CanvasRef;//画布信息
    const widthCenter = d3Canvas.offsetWidth / 2 //中心线
    //裸眼井
    const openHole = { left: undefined, right: undefined, bottom: undefined }
    const waveLeft = d3
        .line()
        .curve(d3.curveBasis)
        .y((d, i) => i)
        .x((d) => Math.sin(d) * 2 + widthCenter - (width / 2));
    const waveRight = d3
        .line()
        .curve(d3.curveBasis)
        .y((d, i) => i)
        .x((d) => Math.sin(d) * 2 + widthCenter + (width / 2));
    const lineData = Array.from(
        { length: height },
        (_, i) => (Math.PI / 2) * i
    );
    openHole.left = $.append("path")
        .attr("d", waveLeft(lineData))
        .attr("fill", "none")
        .attr("stroke", "black")
        .attr("stroke-width", 2)
    openHole.right = $.append("path")
        .attr("d", waveRight(lineData))
        .attr("fill", "none")
        .attr("stroke", "black")
        .attr("stroke-width", 2)
    openHole.bottom = $.append("line")
        .attr("x1", widthCenter - (width / 2))
        .attr("y1", height - 5)
        .attr("x2", widthCenter + (width / 2))
        .attr("y2", height - 5)
        .attr("stroke", "black");
    emitter.on(id, (transform: any) => {
        openHole.left.attr("transform", transform);
        openHole.right.attr("transform", transform);
        openHole.bottom.attr("transform", transform);
    });
    return openHole
}

//删除裸眼井（删）
export function deleteOpenHole($: any) {

}

//修改裸眼井（改）
export function editOpenHole($: any) {

}

//查询裸眼井（查）
export function findOpenHole($: any) {

}
